package org.lixf.biz.impl;

import org.lixf.biz.EmployeeBiz;
import org.lixf.entity.Employee;
import org.lixf.mapper.EmployeeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class EmployeeBizImpl implements EmployeeBiz {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public void add(Employee employee) {
        employee.setPassword("000000");
        employeeMapper.insert(employee);
    }

    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public void edit(Employee employee) {
        employeeMapper.update(employee);
    }

    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public void remove(String sn) {
        employeeMapper.delete(sn);
    }

    @Transactional(readOnly = true)
    public Employee get(String sn) {
        return employeeMapper.select(sn);
    }

    @Transactional(readOnly = true)
    public List<Employee> getAll() {
        return employeeMapper.selectAll();
    }
}
